
package cn.edu.scau.cmi.hombio.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.Calendar;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllPigs", query = "select myPig from Pig myPig"),
		@NamedQuery(name = "findPigByBirthday", query = "select myPig from Pig myPig where myPig.birthday = ?1"),
		@NamedQuery(name = "findPigByEarNumber", query = "select myPig from Pig myPig where myPig.earNumber = ?1"),
		@NamedQuery(name = "findPigById", query = "select myPig from Pig myPig where myPig.id = ?1"),
		@NamedQuery(name = "findPigByMemo", query = "select myPig from Pig myPig where myPig.memo = ?1"),
		@NamedQuery(name = "findPigByMemoContaining", query = "select myPig from Pig myPig where myPig.memo like ?1"),
		@NamedQuery(name = "findPigByNumber", query = "select myPig from Pig myPig where myPig.number = ?1"),
		@NamedQuery(name = "findPigByNumberContaining", query = "select myPig from Pig myPig where myPig.number like ?1"),
		@NamedQuery(name = "findPigByPrimaryKey", query = "select myPig from Pig myPig where myPig.id = ?1"),
		@NamedQuery(name = "findPigByRfid", query = "select myPig from Pig myPig where myPig.rfid = ?1"),
		@NamedQuery(name = "findPigByRfidContaining", query = "select myPig from Pig myPig where myPig.rfid like ?1"),
		@NamedQuery(name = "findPigByState", query = "select myPig from Pig myPig where myPig.state = ?1") })

@Table(catalog = "pig", name = "pig")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain", name = "Pig")
@XmlRootElement(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain")
public class Pig implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "Id", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@Id @GeneratedValue
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "Number", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String number;
	/**
	 */

	@Column(name = "EarNumber")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	Integer earNumber;
	/**
	 */

	@Column(name = "RFID")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String rfid;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "Birthday", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	Calendar birthday;
	/**
	* Ĭ�����ǻ��������ģ���������������ʲô�ģ�״̬��Ϊ0
	* 
	 */

	@Column(name = "State", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	Boolean state;
	/**
	 */

	@Column(name = "Memo")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String memo;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PigTypeId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	PigType pigType;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "FemaleParentId", referencedColumnName = "Id") })
	@XmlTransient
	Pig pigByFemaleParentId;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "SecondLikelyMaleParentId", referencedColumnName = "Id") })
	@XmlTransient
	Pig pigBySecondLikelyMaleParentId;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "ThirdLikelyMaleParentId", referencedColumnName = "Id") })
	@XmlTransient
	Pig pigByThirdLikelyMaleParentId;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "MostLikelyMaleParentId", referencedColumnName = "Id") })
	@XmlTransient
	Pig pigByMostLikelyMaleParentId;
	/**
	 */
	@OneToMany(mappedBy = "pigByFemaleParentId", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Pig> pigsForMostLikelyMaleParentId;
	/**
	 */
	@OneToMany(mappedBy = "pig", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.PigWeight> pigWeights;
	/**
	 */
	@OneToMany(mappedBy = "pigByFemaleParentId", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Pig> pigsForThirdLikelyMaleParentId;
	/**
	 */
	@OneToMany(mappedBy = "pig", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.TaskPig> taskPigs;
	/**
	 */
	@OneToMany(mappedBy = "pigByFemaleParentId", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Pig> pigsForSecondLikelyMaleParentId;
	/**
	 */
	@OneToMany(mappedBy = "pig", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Transfer> transfers;
	/**
	 */
	@OneToMany(mappedBy = "pig", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.SalePig> salePigs;
	/**
	 */
	@OneToMany(mappedBy = "pigByFemaleParentId", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Pig> pigsForFemaleParentId;
	/**
	 */
	@OneToMany(mappedBy = "pig", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.CurePig> curePigs;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setNumber(String number) {
		this.number = number;
	}

	/**
	 */
	public String getNumber() {
		return this.number;
	}

	/**
	 */
	public void setEarNumber(Integer earNumber) {
		this.earNumber = earNumber;
	}

	/**
	 */
	public Integer getEarNumber() {
		return this.earNumber;
	}

	/**
	 */
	public void setRfid(String rfid) {
		this.rfid = rfid;
	}

	/**
	 */
	public String getRfid() {
		return this.rfid;
	}

	/**
	 */
	public void setBirthday(Calendar birthday) {
		this.birthday = birthday;
	}

	/**
	 */
	public Calendar getBirthday() {
		return this.birthday;
	}

	/**
	* Ĭ�����ǻ��������ģ���������������ʲô�ģ�״̬��Ϊ0
	* 
	 */
	public void setState(Boolean state) {
		this.state = state;
	}

	/**
	* Ĭ�����ǻ��������ģ���������������ʲô�ģ�״̬��Ϊ0
	* 
	 */
	public Boolean getState() {
		return this.state;
	}

	/**
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 */
	public String getMemo() {
		return this.memo;
	}

	/**
	 */
	public void setPigType(PigType pigType) {
		this.pigType = pigType;
	}

	/**
	 */
	@JsonIgnore
	public PigType getPigType() {
		return pigType;
	}

	/**
	 */
	public void setPigByFemaleParentId(Pig pigByFemaleParentId) {
		this.pigByFemaleParentId = pigByFemaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Pig getPigByFemaleParentId() {
		return pigByFemaleParentId;
	}

	/**
	 */
	public void setPigBySecondLikelyMaleParentId(Pig pigBySecondLikelyMaleParentId) {
		this.pigBySecondLikelyMaleParentId = pigBySecondLikelyMaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Pig getPigBySecondLikelyMaleParentId() {
		return pigBySecondLikelyMaleParentId;
	}

	/**
	 */
	public void setPigByThirdLikelyMaleParentId(Pig pigByThirdLikelyMaleParentId) {
		this.pigByThirdLikelyMaleParentId = pigByThirdLikelyMaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Pig getPigByThirdLikelyMaleParentId() {
		return pigByThirdLikelyMaleParentId;
	}

	/**
	 */
	public void setPigByMostLikelyMaleParentId(Pig pigByMostLikelyMaleParentId) {
		this.pigByMostLikelyMaleParentId = pigByMostLikelyMaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Pig getPigByMostLikelyMaleParentId() {
		return pigByMostLikelyMaleParentId;
	}

	/**
	 */
	public void setPigsForMostLikelyMaleParentId(Set<Pig> pigsForMostLikelyMaleParentId) {
		this.pigsForMostLikelyMaleParentId = pigsForMostLikelyMaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Set<Pig> getPigsForMostLikelyMaleParentId() {
		if (pigsForMostLikelyMaleParentId == null) {
			pigsForMostLikelyMaleParentId = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>();
		}
		return pigsForMostLikelyMaleParentId;
	}

	/**
	 */
	public void setPigWeights(Set<PigWeight> pigWeights) {
		this.pigWeights = pigWeights;
	}

	/**
	 */
	@JsonIgnore
	public Set<PigWeight> getPigWeights() {
		if (pigWeights == null) {
			pigWeights = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.PigWeight>();
		}
		return pigWeights;
	}

	/**
	 */
	public void setPigsForThirdLikelyMaleParentId(Set<Pig> pigsForThirdLikelyMaleParentId) {
		this.pigsForThirdLikelyMaleParentId = pigsForThirdLikelyMaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Set<Pig> getPigsForThirdLikelyMaleParentId() {
		if (pigsForThirdLikelyMaleParentId == null) {
			pigsForThirdLikelyMaleParentId = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>();
		}
		return pigsForThirdLikelyMaleParentId;
	}

	/**
	 */
	public void setTaskPigs(Set<TaskPig> taskPigs) {
		this.taskPigs = taskPigs;
	}

	/**
	 */
	@JsonIgnore
	public Set<TaskPig> getTaskPigs() {
		if (taskPigs == null) {
			taskPigs = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.TaskPig>();
		}
		return taskPigs;
	}

	/**
	 */
	public void setPigsForSecondLikelyMaleParentId(Set<Pig> pigsForSecondLikelyMaleParentId) {
		this.pigsForSecondLikelyMaleParentId = pigsForSecondLikelyMaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Set<Pig> getPigsForSecondLikelyMaleParentId() {
		if (pigsForSecondLikelyMaleParentId == null) {
			pigsForSecondLikelyMaleParentId = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>();
		}
		return pigsForSecondLikelyMaleParentId;
	}

	/**
	 */
	public void setTransfers(Set<Transfer> transfers) {
		this.transfers = transfers;
	}

	/**
	 */
	@JsonIgnore
	public Set<Transfer> getTransfers() {
		if (transfers == null) {
			transfers = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Transfer>();
		}
		return transfers;
	}

	/**
	 */
	public void setSalePigs(Set<SalePig> salePigs) {
		this.salePigs = salePigs;
	}

	/**
	 */
	@JsonIgnore
	public Set<SalePig> getSalePigs() {
		if (salePigs == null) {
			salePigs = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.SalePig>();
		}
		return salePigs;
	}

	/**
	 */
	public void setPigsForFemaleParentId(Set<Pig> pigsForFemaleParentId) {
		this.pigsForFemaleParentId = pigsForFemaleParentId;
	}

	/**
	 */
	@JsonIgnore
	public Set<Pig> getPigsForFemaleParentId() {
		if (pigsForFemaleParentId == null) {
			pigsForFemaleParentId = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>();
		}
		return pigsForFemaleParentId;
	}

	/**
	 */
	public void setCurePigs(Set<CurePig> curePigs) {
		this.curePigs = curePigs;
	}

	/**
	 */
	@JsonIgnore
	public Set<CurePig> getCurePigs() {
		if (curePigs == null) {
			curePigs = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.CurePig>();
		}
		return curePigs;
	}

	/**
	 */
	public Pig() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Pig that) {
		setId(that.getId());
		setNumber(that.getNumber());
		setEarNumber(that.getEarNumber());
		setRfid(that.getRfid());
		setBirthday(that.getBirthday());
		setState(that.getState());
		setMemo(that.getMemo());
		setPigType(that.getPigType());
		setPigByFemaleParentId(that.getPigByFemaleParentId());
		setPigBySecondLikelyMaleParentId(that.getPigBySecondLikelyMaleParentId());
		setPigByThirdLikelyMaleParentId(that.getPigByThirdLikelyMaleParentId());
		setPigByMostLikelyMaleParentId(that.getPigByMostLikelyMaleParentId());
		setPigsForMostLikelyMaleParentId(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>(that.getPigsForMostLikelyMaleParentId()));
		setPigWeights(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.PigWeight>(that.getPigWeights()));
		setPigsForThirdLikelyMaleParentId(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>(that.getPigsForThirdLikelyMaleParentId()));
		setTaskPigs(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.TaskPig>(that.getTaskPigs()));
		setPigsForSecondLikelyMaleParentId(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>(that.getPigsForSecondLikelyMaleParentId()));
		setTransfers(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Transfer>(that.getTransfers()));
		setSalePigs(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.SalePig>(that.getSalePigs()));
		setPigsForFemaleParentId(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Pig>(that.getPigsForFemaleParentId()));
		setCurePigs(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.CurePig>(that.getCurePigs()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("number=[").append(number).append("] ");
		buffer.append("earNumber=[").append(earNumber).append("] ");
		buffer.append("rfid=[").append(rfid).append("] ");
		buffer.append("birthday=[").append(birthday).append("] ");
		buffer.append("state=[").append(state).append("] ");
		buffer.append("memo=[").append(memo).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Pig))
			return false;
		Pig equalCheck = (Pig) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
